/*
 *  CTerritory.cpp
 *  RiskAI
 *
 */

#include "Territory.h"

#include <sstream>

//**********************************************************************************
//				CONSTRUCTION/DESTRUCTION
//**********************************************************************************

CTerritory::CTerritory(int iIndex)
	: m_iIndex(iIndex)
	, m_iOwner(-1)
	, m_iArmies(0)
{
}

CTerritory::~CTerritory()
{
}




//**********************************************************************************
//				SETUP
//**********************************************************************************

void
CTerritory::AddBorder(int iIndex)
{
	m_viBorderIndices.push_back(iIndex);
}





//**********************************************************************************
//				CORE FUNCTIONALITY
//**********************************************************************************

int
CTerritory::GetIndex()
{
	return m_iIndex;
}

//==================================================================================

int
CTerritory::GetOwner()
{
	return m_iOwner;
}

//==================================================================================

void
CTerritory::SetOwner(int iPlayer)
{
	m_iOwner = iPlayer;
}

//==================================================================================

void
CTerritory::AddArmies(int iNumArmies)
{
	m_iArmies += iNumArmies;
	if(m_iArmies < 0)
		m_iArmies = 0;
}

//==================================================================================

int
CTerritory::GetNumArmies()
{
	return m_iArmies;
}

//==================================================================================

void
CTerritory::SetNumArmies(int iNumArmies)
{
	m_iArmies = iNumArmies;
}

//==================================================================================

std::vector<int>
CTerritory::GetBorderIndices()
{
	return m_viBorderIndices;
}





//**********************************************************************************
//				PRINTING
//**********************************************************************************

std::string
CTerritory::ToString()
{
	std::ostringstream o;
	
	o << "[Territory #" << m_iIndex << "] Owner: " << m_iOwner
	  << "  Armies: " << m_iArmies << "  Borders: ";
	
	for(unsigned int i=0; i<m_viBorderIndices.size(); i++)
	{
		o << m_viBorderIndices[i] << " ";
	}
	return o.str();
}
